<?php
/**
 * 排课管理-课时管理
 * @copyright (c) Seer All Rights Reserved
 */

require_once 'globals.php';

$Course_Lesson_Model = new Course_Lesson_Model();
$action = $_POST['action'];
$courseID = isset($_GET['courseID']) ? $_GET['courseID'] : '';
$courseBatch = isset($_GET['courseBatch']) ? $_GET['courseBatch'] : '';

//显示在线报名用户(用户一览表检索)
if ($action == '' ) {

	$pwd = '上课时间管理';


	$lessons = $Course_Lesson_Model->lessonSelect($courseID,$courseBatch);
	$courseDetail=$Course_Lesson_Model->courseDetailsSelect($courseID);

	if(!$lessons)
	{
		$Course_Lesson_Model->lessonDataInit($courseID,$courseBatch);
		$lessons=$Course_Lesson_Model->lessonSelect($courseID,$courseBatch);
	}
	include View::getView('header');
	require_once View::getView('course/lesson_arrange');
	include View::getView('footer');View::output();
}
if ($action == 'commit' ) {

	$pwd = '上课时间管理提交';

	$courseID = isset($_POST['courseID']) ? $_POST['courseID'] : '';
	$courseBatch = isset($_POST['courseBatch']) ? $_POST['courseBatch'] : '';
	$lessonCount = isset($_POST['lessonCount']) ? $_POST['lessonCount'] : '';
	$lessonDetail = array(
		'courseID' => $courseID,
		'courseBatch' => $courseBatch,
		'lessonCount' => $lessonCount,
	);
 	$lessons = array();
	for ($i = 1;$i<=$lessonCount;$i++)
	{
		$lessons[] =  array(
			'lessonNum' => $i,
			'lessonTime' => $_POST['lesson_time'.$i],
			'comment' => $_POST['comment'.$i],
		);
	}
	$Course_Lesson_Model->lessonTimeUpdate($lessonDetail,$lessons);
	seerDirect("lesson_arrange.php?courseID={$courseID}&courseBatch={$courseBatch}&active_update=1	");
}
if ($action == 'homeWorkReviewEdit' ) {

	$pwd = '作业/评语编辑';
	$courseID = isset($_POST['courseID']) ? $_POST['courseID'] : '';
	$courseBatch = isset($_POST['courseBatch']) ? $_POST['courseBatch'] : '';
	$lessonNum = isset($_POST['lessonNum']) ? $_POST['lessonNum'] : '';
	$mod = isset($_POST['mod']) ? $_POST['mod'] : '';
	if(!$mod)
	{
		$lessonDetail=$Course_Lesson_Model->getLessonDetail($courseID,$courseBatch,$lessonNum);
	}
	if($mod=="commit")
	{
		$homeWork=isset($_POST['homework']) ? $_POST['homework'] : '';
		$review=isset($_POST['review']) ? $_POST['review'] : '';
		$lessonDetail= array(
			'courseID' => $courseID,
			'courseBatch' => $courseBatch,
			'lessonNum' => $lessonNum,
			'homeWork' => $homeWork,
			'review' => $review,
		);
		$Course_Lesson_Model->homeworkReviewUpdate($lessonDetail);
		$lessonDetail=$Course_Lesson_Model->getLessonDetail($courseID,$courseBatch,$lessonNum);
		$updateSuc="Succ";
	}
	 include View::getView('header');
	 require_once View::getView('course/homeworkReviewEdit');
	 include View::getView('footer');View::output();
}